﻿Option Strict On
Option Explicit On
Imports AuthorizeNet
Imports System.Globalization

Partial Class private_secure_members_manage_MyCredit
    Inherits System.Web.UI.Page

    Dim u As MembershipUser
    Dim personId As Int32
    Dim delid As Integer
    Dim entityid As Integer

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        u = Membership.GetUser(HttpContext.Current.User.Identity.Name)

        Dim getpersonid As New GetPersonIdFromUserId()

        personId = getpersonid.GetPersonId(CType(u.ProviderUserKey, Guid))
        Dim entityidTA As New LogginsLogDSTableAdapters.usp_GetEntityListFull_ByPersonIdTableAdapter()
        Dim entityidDT As LogginsLogDS.usp_GetEntityListFull_ByPersonIdDataTable
        entityidDT = entityidTA.GetData(personId)
        If Not Page.IsPostBack Then
            If Not Session("EntityID") Is Nothing Then
                ddlEntity.SelectedValue = CStr(Session("EntityID"))
                btnBuyCredit.Enabled = True
            Else
                BuyButtonState()
            End If
        Else
            BuyButtonState()
        End If

        Try
            GridView1.DataBind()
        Catch ex As Exception

        End Try
    End Sub

    Sub BuyButtonState()
        If CInt(ddlEntity.SelectedValue) = 0 Then
            btnBuyCredit.Enabled = False
        Else
            btnBuyCredit.Enabled = True
        End If
    End Sub


    Protected Sub SqlEntity_ds_Selecting(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles SqlEntity_ds.Selecting
        e.Command.Parameters("@PersonId").Value = CType(personId, Integer)
    End Sub

    Protected Sub btnBuyCredit_Click(sender As Object, e As System.EventArgs) Handles btnBuyCredit.Click
        'Because the user is paying money make sure that no one else is spending money on their behalf
        'So ask them for their credentials again even though they are logged in

        'Now pop up a box allowing the user to purchase credits - 10, 20, 50, 100, 200, 500, 1000
        If CInt(ddlEntity.SelectedValue) = 0 Then
            MsgBox("Please select entity first.")
        Else
            Session("SelectedEntityID") = ddlEntity.SelectedValue
            Response.Redirect("~/private/secure_members/payment/BuyCredit.aspx")
        End If



    End Sub

    Protected Sub ddlEntity_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlEntity.SelectedIndexChanged
        If CInt(ddlEntity.SelectedValue) = 0 Then
            Session.Remove("EntityID")
        Else
            Session("EntityID") = ddlEntity.SelectedValue

        End If
    End Sub

    Protected Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
        Response.Redirect("~/private/default.aspx")
    End Sub

    Protected Sub GridView2_DataBound(sender As Object, e As EventArgs) Handles GridView2.DataBound
        GridView1.DataBind()
    End Sub
End Class
